package com.ithiem.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.dubbo.api.OptionsApi;
import com.itheima.dubbo.api.SoulResultApi;
import com.itheima.model.domain.SoulResult;
import com.ithiem.dubbo.mappers.OptionsMapper;
import com.ithiem.dubbo.mappers.SoulResultMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SoulResultApiImpl implements SoulResultApi {
    @Autowired
    private SoulResultMapper soulResultMapper;

    @Override
    public void saveAll(List<SoulResult> soulResults) {
        soulResults.forEach(s->soulResultMapper.insert(s));
    }

    @Override
    public SoulResult queryConclusion(Integer score) {
        LambdaQueryWrapper<SoulResult> lqw = new LambdaQueryWrapper<>();
        lqw.gt(SoulResult::getMaxScore,score);
        lqw.le(SoulResult::getMinScore,score);

        return soulResultMapper.selectOne(lqw);
    }

    @Override
    public SoulResult findById(Long resultId) {
        return soulResultMapper.selectById(resultId);
    }
}
